"use strict";

const Service = require("egg").Service;

class ContontService extends Service {
    //查询渲染
    async check() {
        let sql = "select * from content";
        return await this.app.mysql.query(sql);
    }
    //添加数据
    async add(title, content, img) {
        let sql = "insert into content (title,content,img) values (?,?,?)"; //插入的sql
        let params = [title, content, img];
        let res = await this.app.mysql.query(sql, params);
        return res;
    }
    //删除数据
    async remove(id) {
        let sql = "delete from content where id = ?";
        let params = [id];
        let res = await this.app.mysql.query(sql, params);
        return res;
    }
    //修改数据
    async change(title, content, id) {
        let sql = "update content set title=?,content=? where id=?";
        let params = [title, content, id];
        let res = await this.app.mysql.query(sql, params);
        return res;
    }
}

module.exports = ContontService;
